<?php

namespace App\Process;
use EasySwoole\Component\Process\AbstractProcess;
use EasySwoole\FastCache\Cache as FastCache;

class FastCachQueue extends AbstractProcess
{
    protected function run($arg=[])
    {
        $instance = \EasySwoole\EasySwoole\Config::getInstance();//配置获取
        $process = $instance->getConf("FASTCACHEPROCESS");
        foreach ($process as $item){
            go( function ()use($item){
                while(true){
                    $job = FastCache::getInstance()->getJob($item['jobName']);
                    if ($job === null){
                        \co::sleep($item['noJobSleep']);
                    }else{
                        $jobObjString = $job->getData();
                        $jobObj = json_decode($jobObjString);//obj
                        call_user_func_array(array(new $jobObj->class, $jobObj->action), objectTransitionArray($jobObj->data));
                        // 执行完了要删除或者重发，否则超时会自动重发
                        FastCache::getInstance()->deleteJob($job);
                        //echo("------------------ 执行任务结束 ---------------- \n");
                    }
                }
            });
        }
        echo($this->getProcessName()." runing... ".PHP_EOL);
    }
}